package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.CategoriesService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Categories;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.CategoriesQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/categories")
@RestController
public class CategoriesController extends BaseController {
	@Resource
	private CategoriesService categoriesService;

	@RequestMapping("/list")
	public ResponseVo getDataList(CategoriesQuery query){
		return getSuccessResponseVo(this.categoriesService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Categories bean){
		this.categoriesService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Categories bean){
		this.categoriesService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Categories> list){
		this.categoriesService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Categories> list){
		this.categoriesService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CategoryID查询
	 */
	@GetMapping("/categoryID")
	public ResponseVo getByCategoryID(Integer categoryID){
		return getSuccessResponseVo(this.categoriesService.getByCategoryID(categoryID));
	}

	/**
	 * 根据CategoryID更新
	 */
	@PutMapping("/categoryID")
	public ResponseVo updateByCategoryID(@Valid Categories bean, Integer categoryID){
		this.categoriesService.updateByCategoryID(bean,categoryID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CategoryID删除
	 */
	@DeleteMapping("/categoryID")
	public ResponseVo deleteByCategoryID(Integer categoryID){
		this.categoriesService.deleteByCategoryID(categoryID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CategoryName查询
	 */
	@GetMapping("/categoryName")
	public ResponseVo getByCategoryName(String categoryName){
		return getSuccessResponseVo(this.categoriesService.getByCategoryName(categoryName));
	}

	/**
	 * 根据CategoryName更新
	 */
	@PutMapping("/categoryName")
	public ResponseVo updateByCategoryName(@Valid Categories bean, String categoryName){
		this.categoriesService.updateByCategoryName(bean,categoryName);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CategoryName删除
	 */
	@DeleteMapping("/categoryName")
	public ResponseVo deleteByCategoryName(String categoryName){
		this.categoriesService.deleteByCategoryName(categoryName);
		return getSuccessResponseVo(null);
	}

}